Imagine logging into your bank account, email, or favorite social media site. You enter your password, hit login and you’re in.

But here’s the thing: after you log in, the website doesn’t ask for your password again every time you click a link.

That’s because it remembers you and that’s exactly what cookies were made for.


I. what ?

Cookies are small pieces of data stored in your browser that keep you authenticated.
But what if someone steals your cookie? Well… then they become you.

This is session hijacking, and it’s one of the most dangerous web security threats.


II. why ?

Cookies are tiny text file that websites store in your browser. They help with :

Most login-based websites use session cookies to identify you. They contain a unique session ID that proves you’re logged in.

A cookie might store this after you log in :

 session_id=abc123xyz; Secure; HttpOnly; 

This session ID tells the server that the user is authenticated.
But if an attacker steals this cookie, they can use your account without needing your password.


III. how ?

Let’s take a look at the cookies stored in your browser right now.

If you click the “Show Cookies” button below and see “No cookies found (or blocked by security settings),” don’t be surprised !
Unless you’re visiting shady websites, this is completely normal. It’s a sign that the developers have done their job well.

As a developer, securing cookies is your responsability.
Here’s how you can secure cookies and protect your users :

Express.js route handler for session regeneration

 Set-Cookie: session_id=abc123xyz; Secure; HttpOnly; Max-Age=1800; 

Express.js session security check


IV. conclusion.

Session hijacking is a serious security threat but by correctly configuring cookies, you can greatly reduce the risk and it is your job as a developer.